﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Photos
{
    public partial class Index : ModuleCompanyBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int currentPage = Request["page"] == null ? 1 : int.Parse(Request["page"].ToString());
                int pagSize = 12;

                var context = DB;

                var photos = from b in context.cp_Photos
                           orderby b.CreateDate descending
                           select b;
                //1 . chuyen truy van thanh list

                PagedList<cp_Photo> pl = new PagedList<cp_Photo>(photos, currentPage - 1, pagSize);

                //2 . gan vao repeater

                rpt.DataSource = pl.ToList();
                rpt.DataBind();

                //3 . chuyen thanh thanh phan trang

                Pager pg = new Pager(pagSize, currentPage, pl.TotalItemCount, TabId);

                //4. tao thanh phan trang

                pnPaging.Text = pg.RenderHtml();

            }


        }

        public string UrlImage(string name)
        {
            string rt = "";
            rt = "http://" + PortalAlias.HTTPAlias + "/Images/photos/" + name;
            return rt;

        }
    }
}